/*
 * Licensed Materials - Property of tenxcloud.com
 * (C) Copyright 2023 TenxCloud. All Rights Reserved.
 * 2023-02-09  @author xyinting
 */

package utils

import (
	"fmt"
	"os"
	"time"

	"github.com/redis/go-redis/v9"
)

const (
	EXPIRE_TIME_PHONE_VERIFY_CODE = 60 * time.Second
	EXPIRE_TIME_USER_PWD_RESET    = 5 * time.Minute
)

var rediscli *redis.Client

func GetRedis() *redis.Client {
	return rediscli
}

func init() {
	ip := os.Getenv("REDIS_HOST")
	port := os.Getenv("REDIS_PORT")
	pwd := os.Getenv("REDIS_PWD")

	rediscli = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%s", ip, port),
		Password: pwd,
	})
}

func SMSCodeKey(phone string) string {
	return fmt.Sprintf("verify_sms_code_%s", phone)
}

func UserPwdResetKey(user string) string {
	return fmt.Sprintf("user_pwd_reset_%s", user)
}
